package com.lsa.skienna.challenge.chap9.the110904_SlashMaze;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class SlashMazeSplitter {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(new FileInputStream(new File("data/pc9/slashMaze/110904.inp")));
		int w = sc.nextInt();
		int h = sc.nextInt();
		
		if (w == 0 && h == 0) {
			return;
		}
		
		if (w == 0 || h == 0) {
			return;
		}
		
		char[][] tokens = new char[w][h];
		
		for (int j = 0; j < h; j++) {
			String line = sc.next("[\\\\/]+");
			for (int i = 0; i < w; i++) {
				String token = line.substring(i, i + 1);
				tokens[i][j] = token.charAt(0);
			}
		}
		
		outputPart("data/pc9/slashMaze/110904_1.inp", tokens, 0, 0, 3, 2);
		outputPart("data/pc9/slashMaze/110904_1.inp", tokens, 3, 0, 3, 2);
		outputPart("data/pc9/slashMaze/110904_1.inp", tokens, 0, 2, 3, 2);
		outputPart("data/pc9/slashMaze/110904_1.inp", tokens, 3, 2, 3, 2);
	}
	
	private static void outputPart(String file, char[][] tokens, int x, int y, int w, int h) throws IOException {
		BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(file), true));
		bufferedWriter.write(String.format("%s %s\n", w, h));
		
		for (int j = y; j < y + h; j++) {
			for (int i = x; i < x + w; i++) {
				char c = tokens[i][j];
				bufferedWriter.write(c);
			}
			bufferedWriter.write("\n");
		}
		
		bufferedWriter.close();
	}
	
	private class Task{
		int x;
		int y;
		int w;
		int h;
		
		boolean isInside(int i, int j) {
			return x <= i && y <= j && i < x + w && j < y + h;
		}
	}
}